<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
 <div id="myChart"  style="height:400px"></div>
   <script type="text/javascript">
	myChart.clear();

              require.config({
                  paths: {
                      echarts: '../resource/echart'
                  }
              });

              // 使用
              require(
                  [
                      'echarts',
                      'echarts/chart/bar', // 使用柱状图就加载bar模块，按需加载
                      'echarts/chart/line'
                  ],
                  function (ec) {
                      // 基于准备好的dom，初始化echarts图表
                      myChart = ec.init(document.getElementById('myChart'));
                      option = {

      							title : {
      								'text':'本周项目项目反馈数量',
                                     subtext: '单位:条'
      							},
      							tooltip : {'trigger':'axis'},
      							legend : {
      								x:'right',
      								'data':['正常','非正常'],
      								'selected':{
      									'正常':true,
      									'非正常':true
      								}
      							},
      							toolbox : {
      								'show':true,
      								orient : 'vertical',
      								x: 'right',
      								y: 'center',
      								'feature':{
      									'mark':{'show':true},
      									'dataView':{'show':true,'readOnly':false},
      									'magicType':{'show':true,'type':['line','bar','stack','tiled']},
      									'restore':{'show':true},
      									'saveAsImage':{'show':true}
      								}
      							},
      							calculable : true,
      							grid : {'y':80,'y2':100},
      							xAxis : [{
      								'type':'category',
      								'axisLabel':{'interval':0},
      								'data':[
      									'周一','周二','周三','周四','周五','周六','周日'
      								]
      							}],
      							yAxis : [
      								{
      									'type':'value',
      									'name':''
      								},
      								{
      									'type':'value',
      									'name':''
      								}
      							],
      							series : [
      								{
      									'name':'正常',
      									'type':'bar',
      									'markLine':{
      										symbol : ['arrow','none'],
      										symbolSize : [4, 2],
      										itemStyle : {
      											normal: {
      												lineStyle: {color:'orange'},
      												barBorderColor:'orange',
      												label:{
      													position:'left',
      													formatter:function(params){
      														return params.value;
      													},
      													textStyle:{color:'orange'}
      												}
      											}
      										},
      										'data':[{'type':'average','name':'平均值'}]
      									},
      									'data':[]
      								},
      								{
      									'name':'非正常','yAxisIndex':1,'type':'bar',
      									'data': []
      								}
      							]

      				};
                      myChart.showLoading({text:'正在努力加载...'});
                      // 为echarts对象加载数据
                      myChart.setOption(option);


                      setTimeout(function(){
                         getChartData();//ajax后台交互
                       },200);

                  }
              );


              function getChartData() {
                          //获得图表的options对象
                          // var options = myChart.getOption();
                          //  console.log(options);
                          var proInfoId = $('#proInfoId').val();
                          //通过Ajax获取数据
                          $.ajax({
                              type : "post",
                              async : false, //同步执行
                              url : "ajax-pro-back!getChartDataByWeek.action",
                              data : {'proInfoId':proInfoId},
                              dataType : "json", //返回数据形式为json
                              success : function(result) {
                                  if (result) {
                                      var rs = result.series;
                                      for (var m=0; m< rs.length; m++){
                                           option.series[m].data  = rs[m].data;
                                      }
                                      myChart.setOption(option);
                                  }

                                  myChart.hideLoading();
                              },
                              error : function(errorMsg) {
                                   alert("图表数据失败");
                                  myChart.hideLoading();
                              }
                          });
                      }


          </script>